// Written in the D Programming Language
/*
 * Copyright (c) 2008 OpenGLUtils
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'OpenGLUtils' nor the names of its contributors 
 *   may be used to endorse or promote products derived from this software 
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
module openglutils.DebugGLU;

import openglutils.GLException;
import openglutils.GLError;

import tango.core.Traits;

/// Imports the GLU functions and variables
public import derelict.opengl.glu;

/**
 * A template for checking GLU errors after calling an GLU function.
 * 
 * Params:
 *     args = the arguments for the GLU function 
 * Returns: The called function's return value
 */
public ReturnTypeOf!(typeof(*Fn)) gluCheck(alias Fn)(ParameterTupleOf!(typeof(*Fn)) args)
{
    alias ReturnTypeOf!(typeof(*Fn)) returnT;
    
    static if(is(returnT == void))
    {
        Fn(args);
    } 
    else
    {
    	returnT result = Fn(args);
    }
    
    glCheckError(Fn.stringof);

    static if(!is(returnT == void))
    {
        return result;
    }
}

public alias gluCheck!(derelict.opengl.glu.gluBuild1DMipmaps) gluBuild1DMipmaps;
public alias gluCheck!(derelict.opengl.glu.gluBuild2DMipmaps) gluBuild2DMipmaps;
public alias gluCheck!(derelict.opengl.glu.gluErrorString) gluErrorString;
public alias gluCheck!(derelict.opengl.glu.gluGetString) gluGetString;
public alias gluCheck!(derelict.opengl.glu.gluCylinder) gluCylinder;
public alias gluCheck!(derelict.opengl.glu.gluDisk) gluDisk;
public alias gluCheck!(derelict.opengl.glu.gluPartialDisk) gluPartialDisk;
public alias gluCheck!(derelict.opengl.glu.gluSphere) gluSphere;
public alias gluCheck!(derelict.opengl.glu.gluBeginCurve) gluBeginCurve;
public alias gluCheck!(derelict.opengl.glu.gluBeginPolygon) gluBeginPolygon;
public alias gluCheck!(derelict.opengl.glu.gluBeginSurface) gluBeginSurface;
public alias gluCheck!(derelict.opengl.glu.gluBeginTrim) gluBeginTrim;
public alias gluCheck!(derelict.opengl.glu.gluEndCurve) gluEndCurve;
public alias gluCheck!(derelict.opengl.glu.gluEndPolygon) gluEndPolygon;
public alias gluCheck!(derelict.opengl.glu.gluEndSurface) gluEndSurface;
public alias gluCheck!(derelict.opengl.glu.gluEndTrim) gluEndTrim;
public alias gluCheck!(derelict.opengl.glu.gluDeleteNurbsRenderer) gluDeleteNurbsRenderer;
public alias gluCheck!(derelict.opengl.glu.gluDeleteQuadric) gluDeleteQuadric;
public alias gluCheck!(derelict.opengl.glu.gluDeleteTess) gluDeleteTess;
public alias gluCheck!(derelict.opengl.glu.gluGetNurbsProperty) gluGetNurbsProperty;
public alias gluCheck!(derelict.opengl.glu.gluGetTessProperty) gluGetTessProperty;
public alias gluCheck!(derelict.opengl.glu.gluLoadSamplingMatrices) gluLoadSamplingMatrices;
public alias gluCheck!(derelict.opengl.glu.gluNewNurbsRenderer) gluNewNurbsRenderer;
public alias gluCheck!(derelict.opengl.glu.gluNewQuadric) gluNewQuadric;
public alias gluCheck!(derelict.opengl.glu.gluNewTess) gluNewTess;
public alias gluCheck!(derelict.opengl.glu.gluNextContour) gluNextContour;
public alias gluCheck!(derelict.opengl.glu.gluNurbsCallback) gluNurbsCallback;
public alias gluCheck!(derelict.opengl.glu.gluNurbsCurve) gluNurbsCurve;
public alias gluCheck!(derelict.opengl.glu.gluNurbsProperty) gluNurbsProperty;
public alias gluCheck!(derelict.opengl.glu.gluNurbsSurface) gluNurbsSurface;
public alias gluCheck!(derelict.opengl.glu.gluPwlCurve) gluPwlCurve;
public alias gluCheck!(derelict.opengl.glu.gluQuadricCallback) gluQuadricCallback;
public alias gluCheck!(derelict.opengl.glu.gluQuadricDrawStyle) gluQuadricDrawStyle;
public alias gluCheck!(derelict.opengl.glu.gluQuadricNormals) gluQuadricNormals;
public alias gluCheck!(derelict.opengl.glu.gluQuadricOrientation) gluQuadricOrientation;
public alias gluCheck!(derelict.opengl.glu.gluQuadricTexture) gluQuadricTexture;
public alias gluCheck!(derelict.opengl.glu.gluTessBeginContour) gluTessBeginContour;
public alias gluCheck!(derelict.opengl.glu.gluTessBeginPolygon) gluTessBeginPolygon;
public alias gluCheck!(derelict.opengl.glu.gluTessCallback) gluTessCallback;
public alias gluCheck!(derelict.opengl.glu.gluTessEndContour) gluTessEndContour;
public alias gluCheck!(derelict.opengl.glu.gluTessEndPolygon) gluTessEndPolygon;
public alias gluCheck!(derelict.opengl.glu.gluTessProperty) gluTessProperty;
public alias gluCheck!(derelict.opengl.glu.gluTessNormal) gluTessNormal;
public alias gluCheck!(derelict.opengl.glu.gluTessVertex) gluTessVertex;
public alias gluCheck!(derelict.opengl.glu.gluLookAt) gluLookAt;
public alias gluCheck!(derelict.opengl.glu.gluOrtho2D) gluOrtho2D;
public alias gluCheck!(derelict.opengl.glu.gluPerspective) gluPerspective;
public alias gluCheck!(derelict.opengl.glu.gluPickMatrix) gluPickMatrix;
public alias gluCheck!(derelict.opengl.glu.gluProject) gluProject;
public alias gluCheck!(derelict.opengl.glu.gluScaleImage) gluScaleImage;
public alias gluCheck!(derelict.opengl.glu.gluUnProject) gluUnProject;
